<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/20
 * Time: 16:13
 */
include '../classes/logincheck.php';
include '../classes/conn.php';
$id=$_POST['id'];
$class=$_POST['class'];
if(islogin()!='teacher_login') {
    die("error");
}

//查询班级是否存在
$query_class="select num from class where num='{$class}'";
$res=mysql_query($query_class);
if(!mysql_num_rows($res)){
    die('no_class');
}

//查询privatefile相关信息
$query1="select * from privatefile where Id='{$id}'";
$res=mysql_query($query1);
$row=mysql_fetch_assoc($res);


//复制文件
$dir1=substr($row['path'],8);
$dir1="..".$dir1;
$dir2="../Files/".$_SESSION['t_num']."/shared/".$class.$row['name'];
if(file_exists($dir2)){
    die('file_exist');
}
copy(iconv('UTF-8','gbk',$dir1),iconv('UTF-8','gbk',$dir2));

//插入sharedfile的path
$dir3=substr($dir2,3);
$dir3="requests/".$dir3;
//插入数据
$query3="insert into sharedfile (name, path,class) VALUES ('{$row['name']}','{$dir3}','{$class}')";
mysql_query($query3);
echo '1';